package com.ofsoft.weixin.mp.api;

/**
 * 用户信息接口
 * 
 * @author OF
 * @date 2017年10月16日
 */
public class UserInfoApi extends ApiBase {
	private static String getUserInfoUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=";

	/**
	 * 获取用户基本信息
	 * 
	 * @param accessToken
	 *            访问token
	 * @param openid
	 *            用户唯一标识
	 * @return json
	 */
	public static ApiResponse getUserInfo(String openid) {
		String url = getUserInfoUrl + AccessTokenConfig.getAccessToken()
				+ "&openid=" + openid + "&lang=zh_CN";
		return sendGet(url);

	}

	private static String updateRemarkUrl = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=";

	/**
	 * 设置用户备注名
	 * 
	 * @param openid
	 *            open_id
	 * @param remark
	 *            备注名
	 * @return ApiResponse
	 */
	public static ApiResponse updateRemark(String openid, String remark) {
		String url = updateRemarkUrl + AccessTokenConfig.getAccessToken();
		return sendPost(url,
				ApiRequest.create("open_id", openid).set("remark", remark));

	}

	private static String batchGetUrl = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=";

	/**
	 * 批量获取用户基本信息
	 * 
	 * @param json
	 *            json字符串
	 * @return ApiResponse
	 */
	public static ApiResponse batchGetUser(String json) {
		String url = batchGetUrl + AccessTokenConfig.getAccessToken();
		return sendPost(url, json);
	}

	private static String userGetList = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=";

	/**
	 * 获取用户列表
	 * 
	 * @param openId
	 *            open_id
	 * @param remark
	 *            备注名
	 * @return ApiResponse
	 */
	public static ApiResponse userGetList(String openId) {
		String url = userGetList + AccessTokenConfig.getAccessToken()
				+ "&next_openid=" + openId;
		return sendGet(url);

	}

}
